package prickworlds.game;

import prickworlds.structure.Drawable;

/**
 * Base class for every object in the scene like robots...
 * 
 * @author Faruk Acibal, Richard Dziambor, Christian Holzreuter, Nicolas Winkler
 * 
 */
public abstract class GameObject implements Drawable {
	/**
	 * the x-coordinate of the position
	 */
	public float posX;

	/**
	 * the y-coordinate of the position
	 */
	public float posY;

	/**
	 * creates a {@link GameObject} at the position (0 / 0)
	 */
	public GameObject() {
		posX = 0;
		posY = 0;
	}

	/**
	 * creates a {@link GameObject} at the specified position
	 * 
	 * @param posX
	 * @param posY
	 */
	public GameObject(float posX, float posY) {
		this.posX = posX;
		this.posY = posY;
	}

	/**
	 * calculates the distance between two objects
	 * 
	 * @param object
	 *            the {@link GameObject} to which the function calculates the
	 *            distance
	 * @return the distance between these two objects
	 */
	float distanceTo(GameObject object) {
		float diffX = posX - object.posX;
		float diffY = posY - object.posY;
		return (float) Math.sqrt(diffX * diffX + diffY * diffY);
	}

	/**
	 * calculates the distance to a point
	 * 
	 * @param x
	 *            the x-coordinate of the point
	 * @param y
	 *            the y-coordinate of the point
	 * @return the distance between the object and the point
	 */
	float distanceTo(float x, float y) {
		float diffX = posX - x;
		float diffY = posY - x;
		return (float) Math.sqrt(diffX * diffX + diffY * diffY);
	}
}
